﻿using System;
using System.Collections.Generic;

namespace Cms.Domain
{
    public class Stylesheet : IComparable<Stylesheet>
    {
        private IList<MasterTemplateStylesheet> _associatedMasterTemplates;
        private Site _site;
        private SourceCode _sourceCode;

        public Stylesheet()
        {
            _associatedMasterTemplates = new List<MasterTemplateStylesheet>();
        }

        public virtual int ID { get; set; }

        public virtual string Name { get; set; }
        
        public virtual SourceCode SourceCode
        {
            get { return _sourceCode; }
            set { _sourceCode = value; }
        }
        
        public virtual IList<MasterTemplateStylesheet> AssociatedMasterTemplates
        {
            get { return _associatedMasterTemplates; }
            set { _associatedMasterTemplates = value; }
        }
        
        public virtual Site Site
        {
            get { return _site; }
            set { _site = value; }
        }
        
        public virtual StylesheetContext Context { get; set; }
        
        public virtual string GetCode()
        {
            return _sourceCode != null ? _sourceCode.CurrentVersion.Code : string.Empty;
        }
        
        public virtual void SetCode(string code, Administrator editedBy)
        {
            if (_sourceCode == null)
                _sourceCode = new SourceCode { Site = _site };
            _sourceCode.AddVersion(code, editedBy);
        }

        public virtual int CompareTo(Stylesheet other)
        {
            return this.ID > 0 && this.ID == other.ID ? 0 : 1;
        }
    }
}